def is_prime(n):
  if n <= 1:
    return False
  for i in range(2, int(n**0.5) + 1):
    if n % i == 0:
      return False
  return True
def largest_prime(number):
  number_str = str(number)
  largest_prime = -1
  for i in range(len(number_str)):
    for j in range(i + 1, len(number_str) + 1):
      num = int(number_str[i:j])
      if is_prime(num) and num > largest_prime:
        largest_prime = num
  return largest_prime
number = int(input())
if 999<number<10000:
    largest_prime_number = largest_prime(number)
    if largest_prime_number != -1:
        print(largest_prime_number)
    else:
        print(0)
else:
    print(0)